# $Id: MultMenu.pm,v 1.1 2004/02/21 18:48:07 ibo Exp $
package CGI::FOGE2::MultMenu;

use strict;
use CGI::FOGE2::Tools;

our @ISA = qw(CGI::FOGE2::MultQuestion);

=head1 NAME

MultMenu - a FOGE question where choices are displayed in a menu where
more than one entry may be selected.

=head1 DESCRIPTION

Instead of defining a CGI::FOGE2::Menu simply use a CGI::FOGE2::MultMenu instead!

=cut

sub new {
    my $proto = shift;
    my $class = ref($proto) || $proto;

    my %args = @_;
    my @mandatory_keys = ('title', 'items', 'id');
    my $self =
    {
        id            => undef, # autogen (?)
        default       => undef,	# the default item (was: initial)
        items         => undef, # an array of items (was: choice)
        title         => undef,	# was: label
        ismultiple    => 1,
        ismandatory   => 0,
        isvalidregexp => undef,
        validate      => undef, # func. returning string or false
        stats         => [CGI::FOGE2::StatsSimple->new()],
    };

    bless ($self, $class);
    $self->_construct(\%args, \@mandatory_keys);
    return $self->init();
}

sub serve {
    my $self = shift;

    my $id = $self->{id};
    my $names = $self->generate_field_names();
    my $name = $names->[0];

    my @items = @{$self->{items}};
    #unshift @items, theform->get_bof();

    my %line = (-values => \@items, 
                -name => $name,
                -multiple => $self->{ismultiple},
                );

    if (defined $self->{default}) {
        $line{-default} = $self->{default};
    }

    return table3cols($self->{title},
		      $self->{ismandatory},
		      CGI::popup_menu(%line));
}

1;

# end of MultMenu.pm
